// d:\byte\tiktok-applet-v3 - 智慧天气\pages\mylist\mylist.js
const model = require('../../public/model/env.js');

const url = model.api_pro_url(); // 线上环境
const key = model.key();
const appid = model.appid();
const userid = tt.getStorageSync('userid');

Page({
  data: {
    className: 'containerdark',
    title: '订单列表',
    items: [],
  },
  go_commment: function(event) {
    const index = event.currentTarget.dataset.index;
    const item = this.data.items[index];
    tt.navigateTo({
      url: `../conmmentadd/conmmentadd?pay_order_no=${item.pay_order_no}`,
    });
  },
  // navigateToDetail: function(event) {
  //   const index = event.currentTarget.dataset.index;
  //   const item = this.data.items[index];
  //   tt.navigateTo({
  //     url: `/pages/res/res?order_gua=${item.zhanbugua}&orderid=${item.pay_order_no}&order_bianyao=${item.zhanbubianyao}&order_thing=${item.zhanbuthing}`
  //   });
  // },
  onLoad: function (options) {
    // 页面加载,标题设置
    tt.setNavigationBarTitle({
      title: this.data.title,
    });
    tt.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000000',
    });
    // 页面加载,标题设置结束


    tt.showLoading({
      title: '加载中',
    });
    const requestUrl = `${url}/index.php/api/order_list.php`;
    const options = {
      url: requestUrl,
      data: {
        appid: appid,
        key: key,
        user_id: userid,
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      dataType: 'json',
    };
    console.log(options);
    // 页面加载
    tt.request({
      ...options,
      success: (res) => {
        console.log(res.data);
        this.setData({
          items: res.data.data,
        });
        tt.hideLoading();
      }})
  },
   navigateToDetail: function(event) {
    const index = event.currentTarget.dataset.index;
    const item = this.data.items[index];
    tt.navigateTo({
      url: `/pages/res/res?order_gua=${item.zhanbugua}&orderid=${item.pay_order_no}&order_bianyao=${item.zhanbubianyao}&order_thing=${item.zhanbuthing}`
    });
  },
    upper(e) {
    tt.showToast({
      title: '到最顶部了',
      icon: 'none'
    });
  },
  lower(e) {
    tt.showToast({
      title: '底线，没有更多了',
      icon: 'none'
    });
  },

  // 页面加载
})